package com.gls.service.demo.ribbon.consumer.service.impl;

import com.gls.service.demo.ribbon.consumer.service.HelloService;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

/**
 * @author lizhiyong
 */
@Service
public class HelloServiceImpl implements HelloService {

    @Autowired
    private RestTemplate restTemplate;

    @HystrixCommand(fallbackMethod = "helloServiceFallback")
    @Override
    public String helloService() {
        return restTemplate.getForEntity("http://service-demo/hello", String.class).getBody();
    }

    public String helloServiceFallback() {
        return "error";
    }
}
